package cn.wolfcode.trip.base.domain;

import com.alibaba.druid.support.json.JSONUtils;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.HashMap;

/**
 * 攻略文章
 */
@Data
@JsonIgnoreProperties(value = {"handler", "json"}) //转成json数据时不需要序列化handler属性
public class StrategyDetail extends BaseDomain {
    public static final int STATE_NORMAL = 0; // 草稿
    public static final int STATE_RELEASE = 1; // 发布
    public static final int STATE_DISABLE = -1; // 禁用
    //标题
    private String title;
    // 创建时间
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date createTime;
    //发布时间
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date releaseTime;
    //序号
    private Integer sequence;
    //所属攻略的分类
    private StrategyCatalog catalog;
    //封面
    private String coverUrl;
    //状态
    private Integer state = STATE_NORMAL;
    // 文章内容
    private StrategyContent content;

    public String getStateName() {
        String tempString = "";
        switch (state) {
            case STATE_NORMAL:
                tempString = "草稿";
                break;
            case STATE_RELEASE:
                tempString = "发布";
                break;
            case STATE_DISABLE:
                tempString = "禁用";
                break;
        }
        return tempString;
    }

    public String getJson() {
        HashMap<String, Object> map = new HashMap();
        map.put("id", id);
        map.put("title", title);
        map.put("sequence", sequence);
        map.put("catalogId", catalog.id);
        map.put("strategyId", catalog.getStrategy().id);
        map.put("coverUrl", coverUrl);
        map.put("state", state);
        return JSONUtils.toJSONString(map);
    }

}